<?php
  class newfeeling extends admin{
    function make_extra($buff,&$buff){
      if(isset($_GET['id'])){
	$id = (int)$_GET['id'];
	$last_id = $_GET['id'];
      } else {
	$last_id = $this->get_last_id();
      }

      if($id){
            $edit_query = $this->query("SELECT * FROM ".KLEO_TABLE_PREFIX."blog WHERE id = $id");
            $row = $this->fetch_array($edit_query);
      } else {
            $edit_id = 0;
      }

      $this->tpl_set(array(
	"FEELING_CONTENT" => $row['content'],
	"POST_START" => $row['start'],
	"POST_EXPIRES" => $row['expires'],
	"POST_PASSWORD" => $row['password'],
	"ALLOW_SELECTED" => $allow_selected,
	"NOT_ALLOW_SELECTED" => $not_allow_selected,
	"LAST_ID" => $last_id
      ), false, $buff, $buff);

      if(isset($_POST['status'])){
	$this->apploadlib(KLEO_LIB_DIR.'validate.lib.php', "kleovalidate", $validator);
	$validator->default_validation_error = L_EMPTY_FIELDS;
	$validator->validate = array(
				$_REQUEST['feeling_content'] => array(
					'empty' => false,
					'message' => L_EMPTY_FIELDS.' ('.L_CONTENT.')'
				)
			);

	$validator->do_validation($posting_error);

	if(isset($posting_error)){
		$this->apperror($posting_error[0]['message']);
	}

	if(empty($_REQUEST['expires'])){
		$expires = '2033-01-01 00:00:00';
	} else {
		$expires = $_REQUEST['expires'];
	}

	if(empty($_REQUEST['display'])){
		$display = date("Y-m-d H:i:s");
	} else {
		$display = $_REQUEST['display'];
	}

	$posted = date("Y-m-d H:i:s");

	$status = $_REQUEST['status'];

	$password = $_REQUEST['password'];

	$post_content = $_REQUEST['feeling_content'];

	$allow_comments = $_REQUEST['allow_comments'];

	$aid = $_SESSION['uid'];

	if(!$this->is_post($last_id)){
		
		$this->query("INSERT INTO `".KLEO_TABLE_PREFIX."blog` (
			`id` ,
			`content` ,
			`expires` ,
			`posted` ,
			`display` ,
			`password` ,
			`allow_comments` ,
			`views` ,
			`type` ,
			`aid` ,
			`home` ,
			`status`
		) VALUES (
			NULL , '$post_content', '$expires', '$posted','$display' , '$password', '$allow_comments', '1', '4', '$aid', '1', '$status'
		);");

	} else {
		$this->query("UPDATE `".KLEO_TABLE_PREFIX."blog` SET 
		   `content` = '$post_content',
		   `expires` = '$expires',
		   `posted` = '$posted',
		   `display` = '$display',
		   `password` = '$password',
		   `allow_comments` = '$allow_comments',
		   `status` = '$status'
		WHERE `".KLEO_TABLE_PREFIX."blog`.`id` =$last_id LIMIT 1 ;");
	}


	if(!isset($_SESSION['dashboard_status'])){
	 	$_SESSION['dashboard_status'] = array(0,L_CHANGED_SUCCESFULLY);
	}
      }

    }


  }
?>